package cc.xuanhaojituan.freemarker.utils;


import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;



public class LogHelper {
    private static Logger logger = LogManager.getLogger(LogHelper.class);

    public static void Debug(String log) {
        logger.debug(log);

    }

    public static void Info(String log) {
        logger.info(log);
    }

    public static void Error(String log) {
        logger.error(log);
    }

    public static void Warn(String log) {
        logger.warn(log);
    }

    public static String getStackTrace(Throwable e) {
        StringWriter sw = null;
        PrintWriter pw = null;
        try {
            sw = new StringWriter();
            pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            pw.flush();
            sw.flush();
        } finally {
            if (sw != null) {
                try {
                    sw.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
            if (pw != null) {
                pw.close();
            }
        }
        return sw.toString();
    }
}
